using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;

using System.Reflection;
using Gizmox.WebGUI.Common.Resources;
using Gizmox.WebGUI.Forms;

using System.IO;
using TVC.Layout;

namespace TVC.Modules.Com
{
    /// <summary>
    /// Summary description for CustomWindowPanelControl.
    /// </summary>

    [Serializable()]
    public class LKC : ModuleParent, IHostedApplication
    {
        private TabControl tabControl1;
        private TabPage tbList;
        private TabPage tbDetail;
        private Label label3;
        private TextBox txtLookup;
        private Label label2;
        private TextBox txtDescription;
        private TextBox txtCode;
        private Label label1;
        private Label label8;
        private TextBox txtCategory;
        private DataGridView dgvList;
        private PictureBox pibCategory;
        private Label label5;
        private TextBox txtStatus;
        private TextBox txtDescription1;
        private Label label4;
        private BindingSource bisLOOKUP;
        private IContainer components;
        GridLayout layout = null;
        public LKC()
        {
            // This call is required by the WebGUI Form Designer.
            _strType = "LKC";
            InitializeComponent();

        }

        /// <summary> 
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }
        int idAllowEditLanguage = 1;
        int idAddNew = 60;
        int idEdit = 61;
        int idDelete = 62;
        int idTransferIn = 63;
        int idTransferOut = 64;
        int idPrint = 65;





        protected override void AllowEditLanguage()
        {
            foreach (Control x in tbDetail.Controls)
            {
                if (x is Label)
                {
                    x.DoubleClick += Control_DoubleClick;
                }
                if (x is GroupBox || x is ExpandableGroupBox || x is Panel)
                {
                    x.DoubleClick += Control_DoubleClick;
                    foreach (Control y in x.Controls)
                    {
                        if (y is Label)
                            y.DoubleClick += Control_DoubleClick;
                    }
                }
            }

            ContextMenu menu = new ContextMenu();
            menu.MenuItems.Add(new MenuItem("Edit Language"));
            dgvList.MenuClick += dgvList_MenuClick;
            tabControl1.DoubleClick += tabMain_DoubleClick;
            dgvList.ContextMenu = menu;
        }

        protected override void LoadLanguage(string language)
        {
            foreach (Control x in tbDetail.Controls)
            {
                if (x is Label)
                {
                    clsConfigurarion.GetLabel(this.ToString(), x, language);
                }
                if (x is GroupBox || x is ExpandableGroupBox || x is Panel)
                {
                    clsConfigurarion.GetLabel(this.ToString(), x, language);
                    foreach (Control y in x.Controls)
                    {
                        if (y is Label)
                            clsConfigurarion.GetLabel(this.ToString(), y, language);
                    }
                }
            }

            if (this.Parent is HeaderedPanel)
            {
                HeaderedPanel pln = this.Parent as HeaderedPanel;
                _title = clsConfigurarion.GetLabel(this.ToString(), "", null, language);
            }
        }
        public HostedToolBarElement[] GetToolBarElements()
        {
            ArrayList objElements = new ArrayList();
            if (IsPermis(idAddNew))
                objElements.Add(new HostedToolBarButton("Add New", new IconResourceHandle("Add.png"), "C"));
            if (IsPermis(idEdit))
                objElements.Add(new HostedToolBarButton("Edit", new IconResourceHandle("Edit.png"), "A"));
            if (IsPermis(idAddNew) && IsPermis(idEdit))
                objElements.Add(new HostedToolBarButton("Save", new IconResourceHandle("Save.png"), "S"));
            if (IsPermis(idAddNew))
                objElements.Add(new HostedToolBarButton("Copy", new IconResourceHandle("Copy.png"), "O"));
            if (IsPermis(idDelete))
                objElements.Add(new HostedToolBarButton("Delete", new IconResourceHandle("Delete.png"), "X"));
            objElements.Add(new HostedToolBarSeperator());
            if (IsPermis(idTransferIn))
                objElements.Add(new HostedToolBarButton("clsTransfer In", new IconResourceHandle("Down.png"), "TI"));
            if (IsPermis(idTransferOut))
                objElements.Add(new HostedToolBarButton("clsTransfer Out", new IconResourceHandle("Up.png"), "TO"));
            objElements.Add(new HostedToolBarSeperator());
            if (IsPermis(idPrint))
                objElements.Add(new HostedToolBarButton("Print", new IconResourceHandle("Print.png"), "P"));
            objElements.Add(new HostedToolBarButton("Refresh", new IconResourceHandle("Refresh.png"), "R"));

            return (HostedToolBarElement[])objElements.ToArray(typeof(HostedToolBarElement));
        }



        #region Component Designer generated code
        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(LKC));
            this.tabControl1 = new Gizmox.WebGUI.Forms.TabControl();
            this.tbList = new Gizmox.WebGUI.Forms.TabPage();
            this.dgvList = new Gizmox.WebGUI.Forms.DataGridView();
            this.bisLOOKUP = new Gizmox.WebGUI.Forms.BindingSource(this.components);
            this.tbDetail = new Gizmox.WebGUI.Forms.TabPage();
            this.label5 = new Gizmox.WebGUI.Forms.Label();
            this.txtStatus = new Gizmox.WebGUI.Forms.TextBox();
            this.txtDescription1 = new Gizmox.WebGUI.Forms.TextBox();
            this.label4 = new Gizmox.WebGUI.Forms.Label();
            this.pibCategory = new Gizmox.WebGUI.Forms.PictureBox();
            this.label3 = new Gizmox.WebGUI.Forms.Label();
            this.label8 = new Gizmox.WebGUI.Forms.Label();
            this.txtLookup = new Gizmox.WebGUI.Forms.TextBox();
            this.label2 = new Gizmox.WebGUI.Forms.Label();
            this.txtDescription = new Gizmox.WebGUI.Forms.TextBox();
            this.txtCode = new Gizmox.WebGUI.Forms.TextBox();
            this.txtCategory = new Gizmox.WebGUI.Forms.TextBox();
            this.label1 = new Gizmox.WebGUI.Forms.Label();
            ((System.ComponentModel.ISupportInitialize)(this.tabControl1)).BeginInit();
            this.tabControl1.SuspendLayout();
            this.tbList.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.dgvList)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.bisLOOKUP)).BeginInit();
            this.tbDetail.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.pibCategory)).BeginInit();
            this.SuspendLayout();
            // 
            // tabControl1
            // 
            this.tabControl1.Alignment = Gizmox.WebGUI.Forms.TabAlignment.Bottom;
            this.tabControl1.Appearance = Gizmox.WebGUI.Forms.TabAppearance.Workspace;
            this.tabControl1.Controls.Add(this.tbList);
            this.tabControl1.Controls.Add(this.tbDetail);
            this.tabControl1.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.tabControl1.Location = new System.Drawing.Point(3, 3);
            this.tabControl1.Name = "tabControl1";
            this.tabControl1.SelectedIndex = 0;
            this.tabControl1.Size = new System.Drawing.Size(601, 442);
            this.tabControl1.TabIndex = 0;
            // 
            // tbList
            // 
            this.tbList.Controls.Add(this.dgvList);
            this.tbList.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.tbList.Location = new System.Drawing.Point(4, 22);
            this.tbList.Name = "tbList";
            this.tbList.Size = new System.Drawing.Size(593, 416);
            this.tbList.TabIndex = 0;
            this.tbList.Text = "List";
            // 
            // dgvList
            // 
            this.dgvList.AllowUserToAddRows = false;
            this.dgvList.AutoGenerateColumns = false;
            this.dgvList.BackgroundColor = System.Drawing.Color.White;
            this.dgvList.BorderStyle = Gizmox.WebGUI.Forms.BorderStyle.FixedSingle;
            this.dgvList.ColumnHeadersHeightSizeMode = Gizmox.WebGUI.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dgvList.DataSource = this.bisLOOKUP;
            this.dgvList.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.dgvList.Location = new System.Drawing.Point(0, 0);
            this.dgvList.Name = "dgvList";
            this.dgvList.RowHeadersWidth = 25;
            this.dgvList.RowTemplate.DefaultCellStyle.FormatProvider = new System.Globalization.CultureInfo("en-US");
            this.dgvList.ShowFilterRow = true;
            this.dgvList.Size = new System.Drawing.Size(593, 416);
            this.dgvList.TabIndex = 0;
            this.dgvList.RowHeaderMouseDoubleClick += new Gizmox.WebGUI.Forms.DataGridViewCellMouseEventHandler(this.dgvList_RowHeaderMouseDoubleClick);
            this.dgvList.UseInternalPaging = true;
            this.dgvList.ItemsPerPage = 50;
            // 
            // bisLOOKUP
            // 
            this.bisLOOKUP.DataSource = typeof(DTO.LOOKUPInfo);
            // 
            // tbDetail
            // 
            this.tbDetail.Controls.Add(this.label5);
            this.tbDetail.Controls.Add(this.txtStatus);
            this.tbDetail.Controls.Add(this.txtDescription1);
            this.tbDetail.Controls.Add(this.label4);
            this.tbDetail.Controls.Add(this.pibCategory);
            this.tbDetail.Controls.Add(this.label3);
            this.tbDetail.Controls.Add(this.label8);
            this.tbDetail.Controls.Add(this.txtLookup);
            this.tbDetail.Controls.Add(this.label2);
            this.tbDetail.Controls.Add(this.txtDescription);
            this.tbDetail.Controls.Add(this.txtCode);
            this.tbDetail.Controls.Add(this.txtCategory);
            this.tbDetail.Controls.Add(this.label1);
            this.tbDetail.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.tbDetail.Location = new System.Drawing.Point(0, 0);
            this.tbDetail.Name = "tbDetail";
            this.tbDetail.Size = new System.Drawing.Size(593, 416);
            this.tbDetail.TabIndex = 1;
            this.tbDetail.Text = "Detail";
            // 
            // label5
            // 
            this.label5.AutoSize = true;
            this.label5.Location = new System.Drawing.Point(16, 158);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(46, 13);
            this.label5.TabIndex = 0;
            this.label5.Text = "Status";
            // 
            // txtStatus
            // 
            this.txtStatus.AllowDrag = false;
            this.txtStatus.Location = new System.Drawing.Point(88, 155);
            this.txtStatus.Name = "txtStatus";
            this.txtStatus.Size = new System.Drawing.Size(100, 20);
            this.txtStatus.TabIndex = 5;
            // 
            // txtDescription1
            // 
            this.txtDescription1.AllowDrag = false;
            this.txtDescription1.Location = new System.Drawing.Point(88, 129);
            this.txtDescription1.Name = "txtDescription1";
            this.txtDescription1.Size = new System.Drawing.Size(436, 20);
            this.txtDescription1.TabIndex = 4;
            // 
            // label4
            // 
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(16, 132);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(46, 13);
            this.label4.TabIndex = 0;
            this.label4.Text = "Description 1";
            // 
            // pibCategory
            // 
            this.pibCategory.BackColor = System.Drawing.Color.Transparent;
            this.pibCategory.BackgroundImageLayout = Gizmox.WebGUI.Forms.ImageLayout.Center;
            this.pibCategory.Image = new Gizmox.WebGUI.Common.Resources.ImageResourceHandle(resources.GetString("pibCategory.Image"));
            this.pibCategory.Location = new System.Drawing.Point(191, 103);
            this.pibCategory.Name = "pibCategory";
            this.pibCategory.Size = new System.Drawing.Size(20, 20);
            this.pibCategory.SizeMode = Gizmox.WebGUI.Forms.PictureBoxSizeMode.CenterImage;
            this.pibCategory.TabIndex = 2;
            this.pibCategory.TabStop = false;
            this.pibCategory.Click += new System.EventHandler(this.pibCategory_Click);
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(16, 41);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(35, 13);
            this.label3.TabIndex = 0;
            this.label3.Text = "Look Up";
            // 
            // label8
            // 
            this.label8.AutoSize = true;
            this.label8.Location = new System.Drawing.Point(16, 106);
            this.label8.Name = "label5";
            this.label8.Size = new System.Drawing.Size(46, 13);
            this.label8.TabIndex = 0;
            this.label8.Text = "Category";
            // 
            // txtLookup
            // 
            this.txtLookup.AllowDrag = false;
            this.txtLookup.Location = new System.Drawing.Point(88, 38);
            this.txtLookup.MaxLength = 15;
            this.txtLookup.Name = "txtLookup";
            this.txtLookup.Size = new System.Drawing.Size(100, 20);
            this.txtLookup.TabIndex = 1;
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(16, 67);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(35, 13);
            this.label2.TabIndex = 0;
            this.label2.Text = "Description";
            // 
            // txtDescription
            // 
            this.txtDescription.AllowDrag = false;
            this.txtDescription.Location = new System.Drawing.Point(88, 64);
            this.txtDescription.Name = "txtDescription";
            this.txtDescription.Size = new System.Drawing.Size(436, 20);
            this.txtDescription.TabIndex = 2;
            // 
            // txtCode
            // 
            this.txtCode.AllowDrag = false;
            this.txtCode.Location = new System.Drawing.Point(88, 12);
            this.txtCode.MaxLength = 15;
            this.txtCode.Name = "txtCode";
            this.txtCode.Size = new System.Drawing.Size(100, 20);
            this.txtCode.TabIndex = 0;
            // 
            // txtCategory
            // 
            this.txtCategory.AllowDrag = false;
            this.txtCategory.Location = new System.Drawing.Point(88, 103);
            this.txtCategory.Name = "txtCategory";
            this.txtCategory.Size = new System.Drawing.Size(100, 20);
            this.txtCategory.TabIndex = 3;
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(16, 15);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(35, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = "Code";
            // 
            // LKC
            // 
            this.Controls.Add(this.tabControl1);
            this.DockPadding.All = 3;
            this.Location = new System.Drawing.Point(0, -10);
            this.Padding = new Gizmox.WebGUI.Forms.Padding(3);
            this.Size = new System.Drawing.Size(607, 448);
            this.Load += new System.EventHandler(this.LOOKUP_Load);
            ((System.ComponentModel.ISupportInitialize)(this.tabControl1)).EndInit();
            this.tabControl1.ResumeLayout(false);
            this.tbList.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.dgvList)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.bisLOOKUP)).EndInit();
            this.tbDetail.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.pibCategory)).EndInit();
            this.ResumeLayout(false);

        }
        #endregion


        #region IHostedApplication Members

        public void InitializeApplication()
        {
        }

        public void addRecord()
        {

        }
        public void SetObject(object obj)
        {
        }


        public void OnToolBarButtonClick(HostedToolBarButton objButton, EventArgs objEvent)
        {
            try
            {
                sErr = "";
                string strAction = (string)objButton.Tag;

                BUS.LOOKUPControl ctr = new BUS.LOOKUPControl();
                switch (strAction)
                {
                    case "C":
                        tabControl1.SelectedTab = tbDetail;
                        RefeshForm("");
                        EnableForm(true);
                        break;
                    case "A":
                        if (dgvList.CurrentCell != null)
                        {
                            DTO.LOOKUPInfo info = new DTO.LOOKUPInfo((DataRowView)dgvList.CurrentRow.DataBoundItem);
                            if (txtCode.Text != info.Code)
                                SetData(info);
                            EnableForm(true);
                            txtCode.ReadOnly = true;
                            txtCategory.ReadOnly = true;
                            pibCategory.Enabled = false;
                            tabControl1.SelectedTab = tbDetail;
                        }
                        break;
                    case "S":
                        if (layout == null)
                            layout = new GridLayout(MainForm.ServerPath + "Resources\\Layout\\", MainForm.ServerPath + "Documents\\Layout\\" + GetMainForm().PODInfo.USER_ID + "\\", _strType);
                        layout.GetUpDGV(dgvList);
                        layout.SaveLayout();
                        Save(ctr);

                        break;
                    case "O":
                        if (dgvList.CurrentCell != null)
                        {
                            if (txtCode.Text == "")
                            {
                                DTO.LOOKUPInfo info = new DTO.LOOKUPInfo((DataRowView)dgvList.CurrentRow.DataBoundItem);
                                SetData(info);
                            }
                            EnableForm(true);
                            tabControl1.SelectedTab = tbDetail;
                        }
                        break;
                    case "X":
                        Delete(ctr);

                        break;
                    case "TI":
                        Forms.frmTransferIn frmTI = new Forms.frmTransferIn(_strType, GetMainForm());
                        frmTI.ShowDialog();
                        break;
                    case "TO":
                        Forms.frmTransferOut frmTO = new Forms.frmTransferOut(_strType, GetMainForm());
                        frmTO.Show();
                        break;
                    case "R":
                        RefreshList();
                        break;
                    case "P":
                        if (dgvList.CurrentCell != null)
                        {
                            DTO.LOOKUPInfo info = new DTO.LOOKUPInfo((DataRowView)dgvList.CurrentRow.DataBoundItem);
                            DataTable dt = DTO.LOOKUPInfo.ToDataTable();
                            dt.Rows.Add(info.ToDataRow(dt));
                            DataSet ds = new DataSet();
                            ds.Tables.Add(dt);
                            MainForm main = GetMainForm();
                            if (main != null)
                                main.PrintDataSet(ds, _strType);
                        }
                        break;
                }
                _processStatus = strAction;
                if (sErr == "")
                    ThrowMsg("Command: " + _processStatus);
            }
            catch (Exception ex)
            {
                ThrowMsg(ex.Message + Environment.NewLine + ex.Source);
            }
        }

        private void RefreshList()
        {
            GetMainForm().LoadDataTable(_strType);
            Rebind(null);
            if (layout == null)
                layout = new GridLayout(MainForm.ServerPath + "Resources\\Layout\\", MainForm.ServerPath + "Documents\\Layout\\" + GetMainForm().PODInfo.USER_ID + "\\", _strType);
            layout.ResetLayout();
            layout.SetUpDGV(dgvList);
        }

        private void Delete(BUS.LOOKUPControl ctr)
        {
            if (dgvList.CurrentCell != null)
            {
                DTO.LOOKUPInfo info = new DTO.LOOKUPInfo((DataRowView)dgvList.CurrentRow.DataBoundItem);
                if (ctr.IsExist(GetMainForm().DB, info.Code, info.Category))
                {
                    Forms.frmMsg frm = new Forms.frmMsg();
                    frm.FormClosed += delegate(object form, FormClosedEventArgs args)
                    {
                        if (((Gizmox.WebGUI.Forms.Form)form).DialogResult == DialogResult.OK)
                        {
                            ctr.Delete(GetMainForm().DB, info.Code, info.Category);
                            if (sErr == "")
                            {
                                DataTable dt = bisLOOKUP.DataSource as DataTable;
                                //dt.Rows.Remove(((DataRowView)dgvList.CurrentRow.DataBoundItem).Row);
                                GetMainForm().RemoveRecord(_strType, ((DataRowView)dgvList.CurrentRow.DataBoundItem).Row);
                                EnableForm(false);
                                Rebind(dt);
                                sErr = "Delete record " + info.Code + " successful";
                            }

                            ThrowMsg(sErr);

                        }

                    };
                    frm.ShowMsg("Do you want to delete " + info.Code + "?");

                }
                else
                    sErr = clsConfigurarion.GetErrMsg("E0002", language);// "Data is not exist";
            }
        }

        private void Save(BUS.LOOKUPControl ctr)
        {
            if (tabControl1.SelectedTab == tbDetail)
            {
                DTO.LOOKUPInfo info = GetData();
                if (_processStatus == "A")
                {
                    if (ctr.IsExist(GetMainForm().DB, txtCode.Text, txtCategory.Text))
                    {
                        sErr = ctr.Update(info);
                        UpdateRecord(info);
                        sErr = "Update record " + txtCode.Text + " successful";
                    }
                    else
                        sErr = clsConfigurarion.GetErrMsg("E0002", language);// "Data is not exist";
                }
                else if (_processStatus == "C" || _processStatus == "O")
                {
                    if (!ctr.IsExist(GetMainForm().DB, txtCode.Text, txtCategory.Text))
                    {
                        ctr.Add(info, ref sErr);
                        UpdateRecord(info);
                        sErr = "Add record " + txtCode.Text + " successful";
                    }
                    else
                        sErr = clsConfigurarion.GetErrMsg("E0007", language);
                }
                ThrowMsg(sErr);

            }
        }

        private void UpdateRecord(DTO.LOOKUPInfo info)
        {
            //GetMainForm().GetTable(_strType).BeginLoadData();
            DataTable dt = bisLOOKUP.DataSource as DataTable;
            //dt.LoadDataRow(info.ToDataRow(GetMainForm().GetTable(_strType)).ItemArray, LoadOption.OverwriteChanges);
            GetMainForm().UpdateRecord(_strType, info.ToDataRow(GetMainForm().GetTable(_strType)).ItemArray, LoadOption.OverwriteChanges);
            //GetMainForm().GetTable(_strType).EndLoadData();
            EnableForm(false);
            Rebind(dt);
        }
        private void Rebind(DataTable dt)
        {
            if (dt == null)
                bisLOOKUP.DataSource = GetMainForm().GetTable(_strType);
        }
        private void ThrowMsg(string sErr)
        {
            BaseForm x = this.Parent.Parent as BaseForm;
            if (x != null)
            {
                x.SetMsg(sErr);
            }
        }

        private DTO.LOOKUPInfo GetData()
        {
            return new DTO.LOOKUPInfo(GetMainForm().DB
                , txtCode.Text
                , txtCategory.Text
                , txtDescription.Text
                , txtDescription1.Text
                , txtLookup.Text
                , txtStatus.Text
                );

        }

        private void EnableForm(bool p)
        {
            txtCode.ReadOnly = !p;
            txtCategory.ReadOnly = !p;
            txtDescription.ReadOnly = !p;
            txtDescription1.ReadOnly = !p;
            txtLookup.ReadOnly = !p;
            txtStatus.ReadOnly = !p;
            pibCategory.Enabled = p;
        }

        private void SetData(DTO.LOOKUPInfo info)
        {
            txtCode.Text = info.Code;
            txtCategory.Text = info.Category;
            txtDescription.Text = info.Description;
            txtDescription1.Text = info.Description1;
            txtLookup.Text = info.Lookup;
            txtStatus.Text = info.Status;
        }

        private void RefeshForm(string str)
        {
            txtCode.Text = str;
            txtCategory.Text = str;
            txtDescription.Text = str;
            txtDescription1.Text = str;
            txtLookup.Text = str;
            txtStatus.Text = str;
        }

        #endregion

        private void LOOKUP_Load(object sender, EventArgs e)
        {
            dgvList.AutoGenerateColumns = false;
            if (!GetMainForm().IsContainsTables(_strType))
                GetMainForm().LoadDataTable(_strType);
            Rebind(null);
            layout = new GridLayout(MainForm.ServerPath + "Resources\\Layout\\", MainForm.ServerPath + "Documents\\Layout\\" + GetMainForm().PODInfo.USER_ID + "\\", _strType);
            //layout.LoadLayout();
            layout.SetUpDGV(dgvList);
            EnableForm(false);
            if (idAllowEditLanguage >= GetMainForm().Permission.Length || GetMainForm().Permission[idAllowEditLanguage] == 'Y')
                AllowEditLanguage();

        }

        private void pibCategory_Click(object sender, EventArgs e)
        {
            Forms.frmView frm = new Forms.frmView("CAT", GetMainForm());
            frm.FormClosed += delegate(object form, FormClosedEventArgs args)
            {
                if (((Forms.frmView)form).DialogResult == DialogResult.OK)
                {
                    txtCategory.Text = ((Forms.frmView)form).ReturnValue[((Forms.frmView)form).ReturnValue.Table.PrimaryKey[0]].ToString();
                }
            };
            frm.ShowDialog();
        }

        private void dgvList_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (dgvList.CurrentCell != null)
            {
                DTO.LOOKUPInfo info = new DTO.LOOKUPInfo((DataRowView)dgvList.CurrentRow.DataBoundItem);
                SetData(info);
                EnableForm(false);
                tabControl1.SelectedTab = tbDetail;
                _processStatus = "V";
            }
        }

        //public string GetLanguage()
        //{
        //    return language;
        //}

    }
}
